/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Dao.DisciplinaDao;
import Dao.DisciplinaDaoImplJPA;
import Pojo.Disciplina;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author maione
 */
public class DisciplinaDaoImplJPATeste {
    
    public DisciplinaDaoImplJPATeste() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }
    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}
    
    @Test
    public void inserirDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(9,"POO","ementa-ementa",72);
        assertTrue(disciplinaDao.inserir(disciplina));
    }
           
    @Test
    public void alterarDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(9,"POO","ementa-ementa",102);
        assertTrue(disciplinaDao.alterar(disciplina));
    }
    
    @Test
    public void alterarDaErrado(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(20,"POO","ementa-ementa",102);
        assertFalse(disciplinaDao.alterar(disciplina));
    }
    
    @Test
    public void removerDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(9,"POO","ementa-ementa",72);
        assertTrue(disciplinaDao.remover(disciplina));
    }
    
    @Test
    public void removerDaErrado(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(22,"POO","ementa-ementa",72);
        assertFalse(disciplinaDao.remover(disciplina));
    }
    
    @Test
    public void pesquisarTodosDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        Disciplina disciplina = new Disciplina(9,"POO","ementa-ementa",72);
        disciplinaDao.inserir(disciplina);
        assertNotSame(0,disciplinaDao.pesquisarTodos().size());
    }
    
    @Test
    public void pesquisarPorNomeDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        assertNotSame(0,disciplinaDao.pesquisarPorNome("POO").size());
    }
    
    @Test
    public void pesquisarPorNomeDaErrado(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        assertSame(0,disciplinaDao.pesquisarPorNome("GA").size());
    }
    
    @Test
    public void pesquisarPorIdDaCerto(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        assertNotNull(disciplinaDao.pesquisarPorId(9));
    }
    
    @Test
    public void pesquisarPorIdDaErrado(){
        DisciplinaDao disciplinaDao = new DisciplinaDaoImplJPA();
        assertNull(disciplinaDao.pesquisarPorId(1203));
    }
}